<?php if(!defined('MS_XTIGER')) exit('Access Denied');
/**
 * Created by openXtiger.org.
 * User: xtiger
 * Date: 2009-6-15
 * Time: 11:15:55
 */

/*public */function settingmodel_replace($var, $value='') {
    $db = xt_load('db');
    $db->query('REPLACE INTO '.xt_tname('settings')." (variable, value) VALUES ('$var', '$value')");       
}
/*public */function settingmodel_delete($var) {
    $db = xt_load('db');
    $db->query('DELETE FROM '.xt_tname('settings')."  WHERE variable='$var'");
}
/*public */function settingmodel_variable($var) {
    $db = xt_load('db');
    $query = $db->query('SELECT value FROM '.xt_tname('settings')."  WHERE variable='$var'");
    return $db->result($query, 0);
}
/*public */function settingmodel_updatecache() {
    $db = xt_load('db');
    $_XSC = array();

	$query = $db->query('SELECT variable,value FROM '.xt_tname('settings'));
	while ($set = $db->fetch_array($query)) {
		$_XSC[$set['variable']] = $set['value'];
	}
	$cachefile = MS_CACHEPATH.'./RuntimeSetting.cache.php';
	$cachetext = 'function xt_setting_cache() {return '.xt_implode($_XSC).';}';
	xt_writefile($cachefile, $cachetext, 'php');  
}